<?php
/**
 * Author: Traveler
 * Time  : 2021/12/25 0025 15:56
 */

namespace app\validate;

use app\ErrorCode;
use think\Validate;

class IcafeTechValidate extends Validate
{
    /**
     * 验证规则
     *
     * @var string[]
     */
    protected $rule = [
        'isp_id'    => 'require|integer|gt:0',
        'bandwidth' => 'require|integer|egt:0',
        'ip'        => 'require|ip',
        'mask'      => 'require|ip',
        'gateway'   => 'require|ip',
        'protocol'  => 'require',
        'port'      => 'require|integer|between:1,65535',
        'account'   => 'require',
        'password'  => 'require',
        'device_ip' => 'ip',
        'pc_count'  => 'integer|gt:0',
        'cellphone' => 'mobile'
    ];

    /**
     * 提示信息
     *
     * @var string[]
     */
    protected $message = [
        'isp_id.require'    => ErrorCode::REQUIRE_ISP_ID,
        'isp_id.integer'    => ErrorCode::INVALID_ISP_ID,
        'isp_id.gt'         => ErrorCode::INVALID_ISP_ID,
        'bandwidth.require' => ErrorCode::REQUIRE_BANDWIDTH,
        'bandwidth.integer' => ErrorCode::INVALID_BANDWIDTH,
        'bandwidth.egt'     => ErrorCode::INVALID_BANDWIDTH,
        'ip.require'        => ErrorCode::REQUIRE_IP,
        'ip.ip'             => ErrorCode::INVALID_IP,
        'mask.require'      => ErrorCode::REQUIRE_MASK,
        'mask.ip'           => ErrorCode::INVALID_MASK,
        'gateway.require'   => ErrorCode::REQUIRE_GATEWAY,
        'gateway.ip'        => ErrorCode::INVALID_GATEWAY,
        'protocol.require'  => ErrorCode::REQUIRE_PROTOCOL,
        'port.require'      => ErrorCode::REQUIRE_PORT,
        'port.integer'      => ErrorCode::INVALID_PORT,
        'port.between'      => ErrorCode::INVALID_PORT,
        'account.require'   => ErrorCode::REQUIRE_ACCOUNT,
        'password.require'  => ErrorCode::REQUIRE_PASSWORD,
        'device_ip.ip'      => ErrorCode::INVALID_DEVICE_IP,
        'pc_count.integer'  => ErrorCode::INVALID_PC_COUNT,
        'pc_count.gt'       => ErrorCode::INVALID_PC_COUNT,
        'cellphone.mobile'  => ErrorCode::INVALID_CHARGE_CELLPHONE,
    ];

    /**
     * 验证场景：专线
     *
     * @return IcafeTechValidate
     */
    public function sceneWan(): IcafeTechValidate
    {
        return $this->only(['isp_id', 'bandwidth', 'ip', 'mask', 'gateway', 'protocol', 'port']);
    }

    /**
     * 验证场景：ADSL
     *
     * @return IcafeTechValidate
     */
    public function sceneAdsl(): IcafeTechValidate
    {
        return $this->only(['isp_id', 'bandwidth', 'account', 'password']);
    }

    /**
     * 验证场景：端口镜像
     *
     * @return IcafeTechValidate
     */
    public function sceneMirror(): IcafeTechValidate
    {
        return $this->only(['device_ip']);
    }

    /**
     * 验证场景：净网先锋
     *
     * @return IcafeTechValidate
     */
    public function sceneCnk(): IcafeTechValidate
    {
        return $this->only(['pc_count', 'cellphone']);
    }
}